package com.tanhua.manage;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import com.tanhua.common.enums.SexEnum;
import com.tanhua.common.pojo.AnalysisByDay;
import com.tanhua.common.service.UserLoginLogsService;
import com.tanhua.manage.pojo.Distribution;
import com.tanhua.manage.service.*;
import com.tanhua.manage.vo.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.*;

/**
 * @author Ling
 * @Title: null.java
 * @Package com.tanhua.manage
 * @Description:
 * @date 2021/9/11 17:56
 */
@SpringBootTest
@RunWith(SpringRunner.class)
public class testmanage {
    @Autowired
    UserLoginLogsService userLoginLogsService;

    @Autowired
    UserInfoService userInfoService;

    @Autowired
    ManageService manageService;

    @Autowired
    AnalysisByDayService analysisByDayService;

    @Autowired
    DashboardService dashboardService;

    //    注册用户分布，行业top、年龄、性别、地区
    @Test
    public void t1() {
        Long sd = 1564588800000L;
        Long ed = 1568131200000L;
        Date start = new Date(sd);
        Date end = new Date(ed);
//        String start1 = DateUtil.formatDateTime(start);
//        String end1 = DateUtil.formatDateTime(end);

        List<Map<String, Object>> maps = userInfoService.countAgeDistribution(start, end);
        List<Map<String, Object>> maps2 = userInfoService.countLocalDistribution(start, end);
//        List<Map<String, Object>> maps1 = userInfoService.countIndustryDistribution(start1, end1);
        System.out.println(maps2);
        List<Distribution> industryDistribution = new ArrayList<>();
        for (Map<String, Object> map : maps2) {
            Distribution distribution = new Distribution();
            distribution.setTitle(map.get("city").toString());
            Integer count = Convert.toInt(map.get("count"));
            distribution.setAmount(count);
            industryDistribution.add(distribution);
        }
//        System.out.println(industryDistribution);
//        System.out.println(maps1);
//        System.out.println(SexEnum.MAN.name());
//        System.out.println(SexEnum.MAN.getValue());
//        System.out.println(SexEnum.MAN.toString());

    }

    //    视频记录翻页
    @Test
    public void t2() {
        PageResult videosListByUserId = manageService.getVideosListByUserId(1L, 1, 10, null, null);
        List<?> items = videosListByUserId.getItems();
        System.out.println("items = " + items);
    }

//    5fae53927e52992e78a3aecd


    //    消息置顶
//    评论列表翻页
//    消息取消置顶
//    消息详情
    @Test
    public void t3() {
        String id = "5fae53927e52992e78a3aecd";
//        Map<String, String> map = manageService.topMessages(id);
//        System.out.println(map);
//        Map<String, String> map2 = manageService.topMessages(id);
//        System.out.println(map2);
//        PageResult comments = manageService.getComments(id, 1, 10, null, null);
//        System.out.println(comments);
        MessagesVo message = manageService.getMessage(id);
        System.out.println("message = " + message);
    }

    //    用户冻结操作
//    用户解冻操作
    @Test
    public void t4() {
//        Map<String, String> map = manageService.freezeUser(1L, 1, 1, "被举报", "mark");
//        System.out.println("map = " + map);

//        Map<String, String> map2 = manageService.unfreezeUser(3L, "被误举报mark");
//        System.out.println("map = " + map2);
    }

    //    用户基本资料
    @Test
    public void t5() {
        UsersInfoVo usersInfo = manageService.getUsersInfo(1L);
        System.out.println("usersInfo = " + usersInfo);


    }

    //测试登录日志记录
    @Test
    public void t6() {
//        Boolean aBoolean =
//        System.out.println("aBoolean = " + aBoolean);
        Random random = new Random();
//        System.out.println("i1 = " + i1);
        for (int i = 0; i < 200; i++) {
            userLoginLogsService.saveLoginLogs(Convert.toLong(random.nextInt(99) + 1));
        }
    }

    //测试日志翻页
    @Test
    public void t7() {
        PageResult loginLogs = manageService.getLoginLogs(1L, 1, 10, null, null);
        List<?> items = loginLogs.getItems();
        System.out.println("items = " + items);
    }

    @Test
    public void t8() {
//        PageResult usersList = manageService.getUsersList(10, 10, null, null, null);
//        System.out.println("usersList = " + usersList);
//        analysisByDayService.saveRecords();
//        AnalysisByDay toDay = analysisByDayService.queryAnalysisToDay();
//        System.out.println("toDay = " + toDay);
//        SummaryVo summary = dashboardService.getSummary();
//        System.out.println("summary = " + summary);

        UsersDistributionVo users = dashboardService.getUsers(DateUtil.offsetWeek(new Date(), -1).getTime(), System.currentTimeMillis(), "101");
        System.out.println("users = " + users);
    }

    @Test
    public void t9() {

    }




}
